/*
 * SupplierDataProvider.java
 * 
 * Created: Aug 4, 2015
 * 
 * Copyright (c) ExpertPB 2015
 * All information contained herein is, and remains the property of
 * ExpertPB and its suppliers, if any.
 */
package com.emex.app.stuff.provider;

import com.emex.app.shared.data.Repayment;
import com.emex.app.shared.data.Supplier;
import com.emex.app.shared.data.SupplierMoney;
import com.emex.app.shared.ws.SupplierWebService;
import com.emex.app.stuff.utils.WebServiceHelper;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;

/**
 *
 * @author Sergey Karavaev
 */
public class SupplierDataProvider extends Service {

    private SupplierWebService service = null;

    private static SupplierDataProvider instance = null;

    /**
     * Constructor
     */
    private SupplierDataProvider() throws MalformedURLException {
        super(new URL(WebServiceHelper.getDefault().getWebServiceURL("web", "Supplier")),
                WebServiceHelper.getDefault().getWebServiceQName("Supplier"));
        service = getPort(SupplierWebService.class);
    }

    /**
     * Get instance of data provider.
     *
     * @return data provider instance
     */
    public static synchronized SupplierDataProvider getInstance() {
        if (instance == null) {
            new RequestWebService() {
                @Override
                protected void doRequestBody() throws MalformedURLException {
                    instance = new SupplierDataProvider();
                }
            }.doRequest();
        }
        return instance;
    }

    public BindingProvider getBindingSupplier() {
        return (BindingProvider) service;
    }

    public int deleteSupplierByPrimaryKey(Integer id) {
        return service.deleteSupplierByPrimaryKey(id);
    }

    public Supplier insertSupplier(Supplier record) {
        return service.insertSupplier(record);
    }

    public List<Supplier> getAllSuppliers() {
        return service.getAllSuppliers();
    }

    public Supplier updateSupplier(Supplier record) {
        return service.updateSupplier(record);
    }

    public Supplier selectSupplierByPrimaryKey(Integer id) {
        return service.selectSupplierByPrimaryKey(id);
    }

    public int deleteSupplierMoney(Integer id) {
        return service.deleteSupplierMoney(id);
    }

    public SupplierMoney updateSupplierMoney(SupplierMoney record) {
        return service.updateSupplierMoney(record);
    }

    public SupplierMoney insertSupplierMoney(SupplierMoney record) {
        return service.insertSupplierMoney(record);
    }

    public List<SupplierMoney> getPaymentsFromClientBySupplierId(Integer id) {
        return service.getPaymentsFromClientBySupplierId(id);
    }

    public List<SupplierMoney> getPaymentsForSupplierBySupplierId(Integer id) {
        return service.getPaymentsForSupplierBySupplierId(id);
    }

    public List<SupplierMoney> getPaymentsByShopBySupplierId(Integer id) {
        return service.getPaymentsByShopBySupplierId(id);
    }

    public List<SupplierMoney> getReturnedPaymentsBySupplierId(Integer id) {
        return service.getReturnedPaymentsBySupplierId(id);
    }

    public int deleteRepayment(Integer id) {
        return service.deleteRepayment(id);
    }

    public Repayment insertRepayment(Repayment record) {
        return service.insertRepayment(record);
    }

    public Repayment updateRepayment(Repayment record) {
        return service.updateRepayment(record);
    }

    public List<Repayment> getRepaymetsForSupplier(Integer supplierId) {
        return service.getRepaymetsForSupplier(supplierId);
    }
}
